<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>编辑数据上报模板</title>
	<#include "/common/resource.ftl">
	<script type="text/javascript" src="${params.contextPath}/common/ztree/js/jquery.ztree.all.min.js"></script>
    <link rel="stylesheet" type="text/css" href="${params.contextPath}/common/ztree/css/zTreeStyle/zTreeStyle.css"/>
	<script type="text/javascript" src="${params.contextPath}/common/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${params.contextPath}/js/moment.min.js"></script>
	<style>
	.layui-form-label{width: 100px;}
	.layui-input-block{margin-left: 130px;}
	</style>
    <script type="text/javascript">
        $(function () {
       	
        });
    </script>
</head>
<body>
<div class="ui-form" style="padding: 20px;padding-top: 10px;">
    <form class="layui-form ajax-form" action="${params.contextPath}/web/taskCycle/<#if (params.id)??>modify<#else>save</#if>.json" method="post">
        <input type="hidden" name="id" value="${params.id}"/>
        <div class="layui-form-item">
            <label class="layui-form-label">数据上报模板<span class="ui-request">*</span></label>
            <div class="layui-input-block">
            	<select name="refId" id="reportTemplate">
		      </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">优先级<span class="ui-request">*</span></label>
            <div class="layui-input-block">
            	<select name="priority" id="priority" >
		        <option value="1">普通</option>
		        <option value="2">紧急</option>
		        <option value="3">非常紧急</option>
		      </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">数据上报周期<span class="ui-request">*</span></label>
            <div class="layui-input-block">
            	<select name="type" id="cycleType" onchange="PublishTime.builder(this)">
		        <option value="3">按月</option>
		        <option value="2">按周</option>
		        <option value="1">按天</option>
		        <option value="0">一次性</option>
		      </select>
            </div>
        </div>
        <div class="layui-form-item" id="publishDateContent">
            <label class="layui-form-label">数据上报日期<span class="ui-request">*</span></label>
			<div class="layui-input-block">
				<select name="intervalDate" id="publishDate">

				</select>
			</div>
		</div>
		<!-- 
        <div class="layui-form-item" id="publishTimeContent">
            <label class="layui-form-label">发布任务时间<span class="ui-request">*</span></label>
			<div class="layui-input-block">
				<select name="runLine" id="publishTime">
					<option value="0">0时执行</option>
					<option value="1">1时执行</option>
					<option value="2">2时执行</option>
					<option value="3">3时执行</option>
					<option value="4">4时执行</option>
					<option value="5">5时执行</option>
					<option value="6">6时执行</option>
					<option value="7">7时执行</option>
					<option value="8">8时执行</option>
					<option value="9">9时执行</option>
					<option value="10">10时执行</option>
					<option value="11">11时执行</option>
					<option value="12">12时执行</option>
					<option value="13">13时执行</option>
					<option value="14">14时执行</option>
					<option value="15">15时执行</option>
					<option value="16">16时执行</option>
					<option value="17">17时执行</option>
					<option value="18">18时执行</option>
					<option value="19">19时执行</option>
					<option value="20">20时执行</option>
					<option value="21">21时执行</option>
					<option value="22">22时执行</option>
					<option value="23">23时执行</option>
				</select>
			</div>
        </div>-->
        <div class="layui-form-item" id="startLineContent">
            <label class="layui-form-label">计划开始日期<span class="ui-request">*</span></label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" placeholder="yyyy-MM-dd" id="startLine" name="startLine" readonly="readonly" onclick="new WdatePicker({maxDate:'#F{$dp.$D(\'deadLine\')}'})">
            </div>
        </div>
        <div class="layui-form-item" id="deadLineContent">
            <label class="layui-form-label">计划截止日期<span class="ui-request">*</span></label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" placeholder="yyyy-MM-dd" id="deadLine" name="deadLine" readonly="readonly" onclick="new WdatePicker({minDate:'#F{$dp.$D(\'startLine\')}'})">
            </div>
        </div>
        <!-- <div class="layui-form-item">
            <label class="layui-form-label">要求完成时限</label>
            <div class="layui-input-block">
                <input type="text" name="complateTimeCountStr"  class="layui-input" placeholder="要求任务发布后多少小时内处理，单位：小时,最大3位数,如果为空或为0则默认48小时"  maxlength="3" >
            </div>
        </div> -->
        <div class="layui-form-item">
            <label class="layui-form-label">执行单位<span class="ui-required">*</span></label>
            <div class="layui-input-block">
                <input type="hidden" name="actors" id="actors"  class="layui-input">
               	<input type="text" class="layui-input select-tree" readonly="readonly" placeholder="请选择单位" name="actorNames" id="actorNames" p="check:true,id:'#actors',name:'#actorNames',url:'${params.contextPath}/web/organization/tree.json'"/> 
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">说明</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" name="remark" placeholder="计划说明，可输入200个字符" maxlength="200" style="min-height: 60px;"></textarea>
            </div>
        </div>
        <div class="layui-form-item" style="padding-top: 10px;text-align: center;">
            
                <input type="submit" value="保 存" class="layui-btn"/>
            
        </div>
    </form>
</div>
<script>
$(document).ready(function(){
	PublishTime.builder($("#cycleType"));
	initReportTemplate();
});
// 加载模板信息
function initReportTemplate(){
	$.ajaxRequest({
        url:'${params.contextPath}/web/reportTemplate/all.json',
        success:function (data) {
            if (data.success != true) {
                layer.msg(data.message);
                return;
            }
            var record = data.data;
            var options = "";
            for (var i=0; i<record.length; i++) {
            	options = options + '<option value="'+record[i].id+'">'+record[i].name+'</option>';
            }
            $("#reportTemplate").append(options);
            
            initRecord();
        }
    });
}
//加载记录信息 
function initRecord(){
	<#if (params.id)??>
    $.ajaxRequest({
        url: '${params.contextPath}/web/taskCycle/query.json',
        data: {id: "${params.id}"},
        success: function (data) {
            if (!data.success) {
                $.message(data.message);
                return;
            }
            var record = data.data;
            for (var key in record) {
            	if(key == "refId"){
            		//alert(key+" "+record[key]);
            		if($("#reportTemplate option[value='"+record[key]+"']").length==0){
            			alert("该模板已删除或停用.");
            		}
            		$("#reportTemplate option[value='"+record[key]+"']").attr("selected",true);
            	}
            	
            	if(key == "type"){
                	switch (record["type"]) {
					case 0:
						$("#publishDateContent").hide();
						//$("#publishTimeContent").hide();
						$("#deadLineContent").hide();
						$("#startLineContent").hide();
						break;
					case 1:
						$("#publishDate").empty();
						PublishTime._day();
						$("[name='runLine']").val(record['runLine']);
						$("[name='deadLine']").val(moment(new Date(record['deadLine'])).format("YYYY-MM-DD"));
						$("[name='startLine']").val(moment(new Date(record['startLine'])).format("YYYY-MM-DD"));
						break;
					case 2:
						$("#publishDate").empty();
						PublishTime._week();
						$("[name='intervalDate']").val(record['intervalDate']);
						$("[name='runLine']").val(record['runLine']);
						$("[name='deadLine']").val(moment(new Date(record['deadLine'])).format("YYYY-MM-DD"));
						$("[name='startLine']").val(moment(new Date(record['startLine'])).format("YYYY-MM-DD"));
						break;
					case 3:
						$("#publishDate").empty();
						PublishTime._month();
						$("[name='intervalDate']").val(record['intervalDate']);
						$("[name='runLine']").val(record['runLine']);
						$("[name='deadLine']").val(moment(new Date(record['deadLine'])).format("YYYY-MM-DD"));
						$("[name='startLine']").val(moment(new Date(record['startLine'])).format("YYYY-MM-DD"));
						break;
					default:
						break;
					}
                	$("[name='type']").val(record['type']);
                }else if(key == "intervalDate"){
        			
        		}else if(key == "runLine"){
        			
        		}else if(key == "deadLine"){
        			
        		}else if(key == "startLine"){
        			
        		}else if(key == "complateTimeCount"){
        			$("[name='complateTimeCountStr']").val(record[key]);
        		}else{
        			$("[name='" + key + "']").val(record[key]);
        		}
            	
            }
           
        }
    });
</#if>
}



var PublishTime = {
	builder:function(obj){
		$("#publishDate").empty();
		$("#publishDateContent").show();
		//$("#publishTimeContent").show();
		$("#deadLineContent").show();
		$("#startLineContent").show();
		var val = $(obj).val();
		if(val=="3"){
			PublishTime._month();
		}else if(val=="2"){
			PublishTime._week();
		}else if(val=="1"){
			PublishTime._day();
		}else{
			$("#publishDateContent").hide();
			//$("#publishTimeContent").hide();
			$("#deadLineContent").hide();
			$("#startLineContent").hide();
		}
		
	}
	,_month:function(){
		var option = null;
		for(var i=1;i<=31;i++){
			option = $("<option></option>");
			option.val(i);
			option.text("每月"+i+"号");
			$("#publishDate").append(option);
		}
	}
	,_week:function(){
		var option = null;
		var weeks=['一','二','三','四','五','六','日'];
		for(var i=1;i<=weeks.length;i++){
			option = $("<option></option>");
			option.val(i);
			option.text("每周"+weeks[i-1]);
			$("#publishDate").append(option);
		}
	},_day:function(){
		$("#publishDateContent").hide();
		var option = null;
		for(var i=0;i<=23;i++){
			option = $("<option></option>");
			option.val(i);
			option.text(i+"时执行");
			$("#publishDate").append(option);
		}
	}
}


/* chageType:function(obj){
	$("#publishDate").empty();
	$("#publishDateContent").show();
	$("#publishTimeContent").show();
	$("#deadLineContent").show();
	var val = $(obj).val();
	if(val=="3"){
		PublishTime._month();
	}else if(val=="2"){
		PublishTime._week();
	}else if(val=="1"){
		PublishTime._day();
	}else{
		$("#publishDateContent").hide();
		$("#publishTimeContent").hide();
		$("#deadLineContent").hide();
	}
}, */


</script>
</body>
</html>
